<?php

namespace App\Console\Commands;

use Illuminate\Support\Facades\DB;
use Illuminate\Console\Command;
use GuzzleHttp\Client;

class Shot extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'shot';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'shot';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        //
        $sites = DB::table('sites')->where(['state'=>'1'])->select('url')->get();
        $client = new Client;
        foreach ($sites as $v){
//            echo $v->url;
            $res = $client->request('POST','http://api.webshowu.com/api/shot',[
                'headers' => [
                    'Authorization' => 'Bearer iIDDVo89XxKv4HMPZmrfRDYyBF3wRTgSod285NOcfqBlnuE6RJ3hl9syi2XZIute',
                ],
                'form_params' => [
                    'name'  => $v->url,
                ]
            ]);
            if($res->getStatusCode() != 200){
                $this->info($v->url.'===error1');
            }else{
                $response   = json_decode($res->getBody());
                if($response->code == 0) {
                    $this->info($v->url.'===ok');
                }else{
                    $this->info($v->url.'===error2');
                }
            }
        }
    }
}
